package com.bootdo.system.service.impl;

import com.bootdo.system.dao.*;
import com.bootdo.system.domain.DlJobDO;
import com.bootdo.system.domain.DlPositionClassDO;
import com.bootdo.system.domain.DlPositionDO;
import com.bootdo.system.domain.DlPositionSubclassDO;
import com.bootdo.system.service.StatisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * @author: 况鑫威
 * @Date: 2021/6/4
 * @Time: 11:27
 * @ClassName: StatisticsServiceImpl
 * @Description: com.bootdo.system.service.impl
 */
@Service
public class StatisticsServiceImpl implements StatisticsService {
    @Autowired
    private DlJobDao dlJobDao;
    @Autowired
    private DlMemberDao dlMemberDao;
    @Autowired
    private DlCompanyDao dlCompanyDao;
    @Autowired
    private DlInterviewDao dlInterviewDao;
    @Autowired
    private DlPositionClassDao dlPositionClassDao;
    @Autowired
    private DlPositionSubclassDao dlPositionSubclassDao;

    @Override
    public Map<String, Object> statistics() {
        //发布的职位数量
        HashMap<String, Object> map = new HashMap<>();
        map.put("openStatus", "1");
        map.put("delFlag", "0");
        List<DlJobDO> count = dlJobDao.list(map);
        HashMap<Integer, Integer> countMap = new HashMap<>();
        HashMap<Integer, Integer> countSubMap = new HashMap<>();
        HashMap<Integer, Integer> countClassMap = new HashMap<>();
        for (DlJobDO dlJobDO : count) {
            //对各个职位进行计数
            if(countMap.containsKey(dlJobDO.getPositionId())){
                countMap.put(dlJobDO.getPositionId(), countMap.get(dlJobDO.getPositionId())+1);
            }else {
                countMap.put(dlJobDO.getPositionId(), 1);
            }
        }

        //通过计数map的key找到
        map.clear();
        Set<Integer> integers = countMap.keySet();
        for (Integer integer : integers) {
            map.put("positionId", integer);
            List<DlPositionSubclassDO> list = dlPositionSubclassDao.list(map);
            for (DlPositionSubclassDO dlPositionSubclassDO : list) {
                map.clear();
                map.put("positionClassId", dlPositionSubclassDO.getPositionClassId());
                List<DlPositionClassDO> list1 = dlPositionClassDao.list(map);
            }
        }


        //线上面试人数
        map.clear();
        map.put("type", "1");
        int i1 = dlInterviewDao.count(map);
        //线下面试人数
        map.clear();
        map.put("type", "2");
        int i2 = dlInterviewDao.count(map);


        //求职者数量
        map.clear();
        map.put("role", "1");
        int count1 = dlMemberDao.count(map);

        //公司审核中
        map.clear();
        map.put("auditStatus", "3");
        int count2 = dlCompanyDao.count(map);
        //公司审核通过
        map.clear();
        map.put("auditStatus", "1");
        int count3 = dlCompanyDao.count(map);
        //公司不通过
        map.clear();
        map.put("auditStatus", "2");
        int count4 = dlCompanyDao.count(map);

        map.clear();
        map.put("jobCount", count.size());
        map.put("i1", i1);
        map.put("i2", i2);
        map.put("memberCount", count1);
        map.put("company3Count", count2);
        map.put("company1Count", count3);
        map.put("company2Count", count4);
        return map;
    }
}
